import {
  TableBaseColumn,
  TableColumnGroup,
  TableSelectionColumn,
  TableExpandColumn,
  InternalRowData
} from 'naive-ui/es/data-table/src/interface'
import { ProTableQueryItem } from '.'
import { DictOptions } from './common'

export type CommonProColumnInfo = {
  type?:
    | 'selection'
    | 'expand'
    | 'dict'
    | 'tag'
    | 'link'
    | 'switch'
    | 'date'
    | 'index'
    | 'operation'
  // 列表元素的配置
  props?: {
    [index: string]: unknown
  }
  key?: string
  title?: string
  // 内置了query的配置，主要应用在当有key、title等相同的搜索项时，可以简写搜索项配置
  query?: Partial<ProTableQueryItem>
  // 字典的配置
  dictOptions?: DictOptions[]
  // 字典的value字段名
  valueCode?: string
  // 字典的label字段名
  labelCode?: string
  // 字典的code唯一表示
  dictCode?: number | string
  // 日期格式化
  format?: string
  // type为switch时的选中文案
  checkedText?: string
  // type为switch时的未选中文案
  uncheckedText?: string
  // 是否展示
  visiable?: boolean
  // 自定义回显
  displayValue?: (row?: any, index?: number) => any
  // 点击事件回调
  click?: (row?: any, index?: number) => any
}

type ProTableBaseColumn<T> = TableBaseColumn<T> & CommonProColumnInfo
type ProTableColumnGroup<T> = TableColumnGroup<T> & CommonProColumnInfo
type ProTableSelectionColumn<T> = Omit<TableSelectionColumn<T>, 'type'> &
  CommonProColumnInfo
type ProTableExpandColumn<T> = Omit<TableExpandColumn<T>, 'type'> &
  CommonProColumnInfo

export type ProTableColumn<T = InternalRowData> =
  | ProTableBaseColumn<T>
  | ProTableColumnGroup<T>
  | ProTableSelectionColumn<T>
  | ProTableExpandColumn<T>

export type ProTableColumns = ProTableColumn[]
